package servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSON;

import bean.Student;
import dao.StudentDao;

/**
 * Servlet implementation class AppStudentServlet
 */
@WebServlet("/AppStudentServlet")
public class AppStudentServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
	// student数据库的操作类

		private StudentDao studentDao = new StudentDao();

		protected void doGet(HttpServletRequest request, HttpServletResponse response)
				throws ServletException, IOException {
			// 查询所有的学生

			List<Student> ss = studentDao.getAllStudent();
			response.setContentType("text/html;charset=utf-8");
			// 将集合打印到客户端

			response.getWriter().print(JSON.toJSON(ss));
		}

		protected void doPost(HttpServletRequest request, HttpServletResponse response)
				throws ServletException, IOException {
			doGet(request, response);
		}

}
